/*
package cn.huaguo.types.utils;

import cn.huaguo.trigger.http.dto.Amount;
import cn.huaguo.trigger.http.dto.PayReqDTO;
import cn.huaguo.trigger.http.dto.Payer;
import com.alibaba.fastjson.JSON;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.security.Signature;
import java.util.Base64;

*/
/**
 * @Author：Arvin
 * @description：微信支付工具类
 * @Date：2024/5/21 13:39
 *//*

public class WxPayUtil {
    private CloseableHttpClient httpClient;
    public void CreateOrder () throws Exception {

        //请求URL
        HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi");
        Amount amount = Amount.builder()
                .total(1)//单位为分
                .currency("CNY")
                .build();
        Payer payer = Payer.builder()
                .openid(openid)
                .build();
        PayReqDTO payReqDTO = PayReqDTO.builder()
                .appid(appid)
                .mchid(mchid)
                .description("测试支付订单")
                .out_trade_no("1001001001")//长度大于6
                .notify_url("")
                .amount(amount)
                .payer(payer)
                .build();
        // 请求body参数
        String reqdata = JSON.toJSONString(payReqDTO);
        StringEntity entity = new StringEntity(reqdata, "utf-8");
        entity.setContentType("application/json");
        httpPost.setEntity(entity);
        httpPost.setHeader("Accept", "application/json");

        //完成签名并执行请求
        CloseableHttpResponse response = httpClient.execute(httpPost);
        try {
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                System.out.println(" 200 success,return body = " + EntityUtils.toString(response.getEntity()));
            } else if (statusCode == 204) {
                System.out.println("success");
            } else {
                System.out.println("failed,resp code = " + statusCode + ",return body = " + EntityUtils.toString(response.getEntity()));
                throw new IOException("request failed");
            }
        } finally {
            response.close();
            httpClient.close();
        }
    }
    String signType = "SHA256withRSA";
    */
/**
     * 获取签名
     *
     * @param nonceStr  随机数
     * @param appId     微信公众号或者小程序等的appid
     * @param prepay_id 预支付交易会话ID
     * @param timestamp 时间戳 10位
     * @return String 新签名
     *//*

    String getSign(String nonceStr, String appId, String prepay_id, long timestamp) {

        //从下往上依次生成
        String message = buildMessage(appId, timestamp, nonceStr, prepay_id);
        //签名
        try {
            return sign(message.getBytes("utf-8"));
        } catch (IOException e) {
            throw new RuntimeException("签名异常,请检查参数或商户私钥");
        }
    }

    String sign(byte[] message) {
        try {
            //签名方式
//            WxPayConstants.SignType.HMAC_SHA256;
            Signature sign = Signature.getInstance(signType);
            //私钥，通过MyPrivateKey来获取，这是个静态类可以接调用方法 ，需要的是_key.pem文件的绝对路径配上文件名
            sign.initSign(wxPayService.getConfig().getPrivateKey());
            sign.update(message);
            return Base64.getEncoder().encodeToString(sign.sign());
        } catch (Exception e) {
            throw new RuntimeException("签名异常,请检查参数或商户私钥");
        }
    }

    */
/**
     * 按照前端签名文档规范进行排序，\n是换行
     *
     * @param nonceStr  随机数
     * @param appId     微信公众号或者小程序等的appid
     * @param prepay_id 预支付交易会话ID
     * @param timestamp 时间戳 10位
     * @return String 新签名
     *//*

    String buildMessage(String appId, long timestamp, String nonceStr, String prepay_id) {
        return appId + "\n"
                + timestamp + "\n"
                + nonceStr + "\n"
                + prepay_id + "\n";
    }
}
*/
